import 'package:data_plugin/bmob/bmob_query.dart';
import 'package:data_plugin/bmob/table/bmob_object.dart';
/// CreateTime 2020/6/16 10:45
/// CreateUser chen 
/// ProjectName flutter_elf
import 'package:flutter_elf/config/component_index.dart';
import 'package:flutter_elf/utils/object_util.dart';

import 'summary_page.dart';
class ZhiYaoDetailPage extends StatefulWidget{
  TitleModel titleModel;

  ZhiYaoDetailPage(this.titleModel);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return ZhiYaoDetailPageState();
  }
}

class ZhiYaoDetailPageState extends State<ZhiYaoDetailPage>{

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getData();
  }

  ZhiyaoModel model = ZhiyaoModel.empty();
  getData(){
    BmobQuery<ZhiyaoModel> query = BmobQuery();
    query.addWhereEqualTo('title', widget.titleModel.title);
    query.queryObjects().then((data) {
      setState(() {
        model = ZhiyaoModel.fromJson(data[0]);
      });
    }).catchError((e) {
      print('===========>error');
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBarCreator.create(context,widget.titleModel.title),
      body: SingleChildScrollView(child: Text(model.isEmpty()  ?  '' : model.content)),
    );
  }
}


class ZhiyaoModel extends BmobObject{
  String articleTitle;//文章的标题
  String url;//连接
  String pictureUrl;//图片链接 class = wp-block-image
  String category;//分类
  String title;//标题  hi post-title
  String content;
  String uuid = '31231231';
  ZhiyaoModel.empty();
  isEmpty(){
    return ObjectUtil.isEmptyString(this.title);
  }
  ZhiyaoModel(this.url, this.pictureUrl, this.category, this.title,
      this.content);
  ZhiyaoModel.fromJson(jsonRes){
    this.articleTitle = jsonRes['articleTitle'];
    this.url = jsonRes['url'];
    this.pictureUrl = jsonRes['pictureUrl'];
    this.category = jsonRes['category'];
    this.title = jsonRes['title'];
    this.content = jsonRes['content'];
    this.uuid = jsonRes['uuid'];
  }
  @override
  Map getParams() {
    Map<String,dynamic> map = {
      'url':this.url,
      'pictureUrl':this.pictureUrl,
      'category':this.category,
      'title':this.title,
      'content':this.content,
      'uuid':this.uuid,
      objectId:objectId
    };
    return map;
  }
}